-
Couldn't load subscription status.
- Fork 168
fix(keymap): use correct derivation_path for keys with origin
#863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(keymap): use correct derivation_path for keys with origin
#863
Conversation
- Fixes the implementation of `GetKey` for `KeyRequest::Bip32` when there's `Xpriv` has an origin, and it matches with the given `KeyRequest::Bip32` derivation_path. It should strip the matching part, to correctly derive the key at the correct child number. - Updates the existing test to the correct and expected behavior.
b8f4d24 to
2f72b27
Compare
| if let Some(matched_path) = descriptor_xkey.matches(key_source, secp) { | ||
| let (_, full_path) = key_source; | ||
|
|
||
| let derivation_path = &full_path[matched_path.len()..]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The matched path includes the xkey.derivation_path, therefore we need to derive the xkey.derivation_path together with the remaining un-matched path. That's my hunch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was never resolved, did you investigate this @oleonardolima?
Is this what you were talking about at the Summit @ValuedMammal or was that a different bug you think you found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, VM explained this issue to me at the summit.
I'm planning on working on this issue and adding more integration tests for different signing scenarios this week.
@ValuedMammal let me know if you found any other issues with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work, following the same implementation in bdk.
if let Some(..) = descriptor_xkey.matches(key_source, secp) {
let (_, full_path) = key_source;
let derived = match &descriptor_xkey.origin {
Some((_, origin_path)) => {
let derivation_path = &full_path[origin_path.len()..];
descriptor_xkey.xkey.derive_priv(secp, &derivation_path)?
}
None => descriptor_xkey.xkey.derive_priv(secp, &full_path)?,
};
return Ok(Some(derived.to_priv()));
}|
Yep, I think this is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 2f72b27; successfully ran local tests
GetKeyforKeyRequest::Bip32when there'sXprivhas an origin, and it matches with the givenKeyRequest::Bip32derivation_path. It should strip the matching part, to correctly derive the key at the correct child number.